package com.ruoyi.web.erp.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.czkt.domain.ErpSpuAttr;
import com.czkt.service.IErpSpuAttrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品属性关联Controller
 * 
 * @author ruoyi
 * @date 2024-04-26
 */
@RestController
@RequestMapping("/system/attr")
public class ErpSpuAttrController extends BaseController
{
    @Autowired
    private IErpSpuAttrService erpSpuAttrService;

    /**
     * 查询商品属性关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:attr:list')")
    @GetMapping("/list")
    public TableDataInfo list(ErpSpuAttr erpSpuAttr)
    {
        startPage();
        List<ErpSpuAttr> list = erpSpuAttrService.selectErpSpuAttrList(erpSpuAttr);
        return getDataTable(list);
    }

    /**
     * 导出商品属性关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:attr:export')")
    @Log(title = "商品属性关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpSpuAttr erpSpuAttr)
    {
        List<ErpSpuAttr> list = erpSpuAttrService.selectErpSpuAttrList(erpSpuAttr);
        ExcelUtil<ErpSpuAttr> util = new ExcelUtil<ErpSpuAttr>(ErpSpuAttr.class);
        util.exportExcel(response, list, "商品属性关联数据");
    }

    /**
     * 获取商品属性关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:attr:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(erpSpuAttrService.selectErpSpuAttrById(id));
    }

    /**
     * 新增商品属性关联
     */
    @PreAuthorize("@ss.hasPermi('system:attr:add')")
    @Log(title = "商品属性关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ErpSpuAttr erpSpuAttr)
    {
        return toAjax(erpSpuAttrService.insertErpSpuAttr(erpSpuAttr));
    }

    /**
     * 修改商品属性关联
     */
    @PreAuthorize("@ss.hasPermi('system:attr:edit')")
    @Log(title = "商品属性关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ErpSpuAttr erpSpuAttr)
    {
        return toAjax(erpSpuAttrService.updateErpSpuAttr(erpSpuAttr));
    }

    /**
     * 删除商品属性关联
     */
    @PreAuthorize("@ss.hasPermi('system:attr:remove')")
    @Log(title = "商品属性关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(erpSpuAttrService.deleteErpSpuAttrByIds(ids));
    }
}
